﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLTV_BLL;
using QLTV_Public;


namespace GUI
{
    public partial class uc_TimKiemTaiLieu : DevExpress.XtraEditors.XtraUserControl
    {
        #region Khai bao bien
        TaiLieu_BLL tl_bll = new TaiLieu_BLL();
        TextMessageBox box = new TextMessageBox();
        #endregion

        #region LoadForm

        public uc_TimKiemTaiLieu()
        {
            InitializeComponent();
        }

        private void uc_TimKiemTaiLieu_Load(object sender, EventArgs e)
        {
            LoadCombobox();
            grv_Data.BestFitColumns();
        }

        #endregion

        #region Cac chuc nang

        private void btnTimKiem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Load_Data();
            lblSoLuong.Caption ="Kết Quả Tìm Kiếm: "+ grv_Data.RowCount.ToString()+"Tài Liệu";
        }

        private void btnHuy_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            cboLinhVuc.Text = "";
            cboNgonNgu.Text = "";
            cboNhaXuatBan.Text = "";
            cboTheLoai.Text = "";
            txtNamXuatBan.Text = "";
            txtNhanDe.Text = "";
            txtPhuDe.Text = "";
            txtTacGia.Text = "";
        }

        #endregion 

        #region Ham viet them

        public void Load_Data()
        {
            TaiLieu_Public tl = new TaiLieu_Public();
            tl.NhanDe = txtNhanDe.Text;
            tl.PhuDe = txtPhuDe.Text;
            tl.TacGiaChinh = txtTacGia.Text;
            tl.NamXuatBan =box.ToInt(txtNamXuatBan.Text);
            grd_Data.DataSource= tl_bll.Search_TaiLieu(tl,cboLinhVuc.Text,cboTheLoai.Text,cboNgonNgu.Text,cboNhaXuatBan.Text);
           
            grv_Data.BestFitColumns();
            //if (dt.Rows.Count > 0)
            //{
            //    StringBuilder str = new StringBuilder();
            //    for (int i = 0; i < dt.Rows.Count; i++)
            //    {
            //        str.Append(i+1+":\r\n Mã Tài Liệu: "+dt.Rows[i]["MaTaiLieu"].ToString()+"\r\n Nhan Đề: "+dt.Rows[i]["NhanDe"].ToString()+"\r\n Phụ Đề: "+dt.Rows[i]["PhuDe"].ToString()+"\r\n Tác Giả: "+dt.Rows[i]["TacGiaChinh"].ToString()+"\r\n Tóm Tắt Nội Dung: "+dt.Rows[i]["TomTatNoiDung"].ToString()+"\r\n Lần Tái Bản: "+dt.Rows[i]["LanTaiBan"].ToString()+"\r\n Năm Xuất Bản: "+dt.Rows[i]["NamXuatBan"].ToString()+"\r\n Ngôn Ngữ: "+dt.Rows[i]["TenNgonNgu"].ToString()+"\r\n Lĩnh Vực: "+dt.Rows[i]["TenLinhVuc"].ToString()+"\r\n Thể Loại: "+dt.Rows[i]["TenTheLoai"].ToString()+"\r\n Nhà Xuất Bản: "+dt.Rows[i]["TenNhaXB"].ToString()+"\r\n Vị Trí Lưu Trữ: "+dt.Rows[i]["TenViTri"].ToString());
            //        str.Append("\r\n*****************************************************************\r\n");
            //    }
            //    txtTaiLieu.Text = str.ToString();
            //}
        }

        private void LoadCombobox()
        {
            cboLinhVuc.Properties.DataSource = tl_bll.TaoBang("select  TenLinhVuc from DM_LinhVuc");
            cboLinhVuc.Properties.DisplayMember = "TenLinhVuc";

            cboNgonNgu.Properties.DataSource = tl_bll.TaoBang("select TenNgonNgu from DM_NgonNgu");
            cboNgonNgu.Properties.DisplayMember = "TenNgonNgu";

            cboNhaXuatBan.Properties.DataSource = tl_bll.TaoBang("select TenNhaXB from DM_NhaXuatBan");
            cboNhaXuatBan.Properties.DisplayMember = "TenNhaXB";

            cboTheLoai.Properties.DataSource = tl_bll.TaoBang("select TenTheLoai from DM_TheLoaiTaiLieu");
            cboTheLoai.Properties.DisplayMember = "TenTheLoai";
        }
        #endregion
    }
}
